﻿(function()
{
    /*################################命名空间开始###########################*/
    /*============================全局变量定义区开始=========================*/
    //此范围内定义的变量与外部同名变量不冲突
    
    /*============================全局变量定义区结束=========================*/
    if (window.XJWindow == null)
    {
        /*****************************XJWindow库开始***************************/
        window.XJWindow =
        {
            /*----------------------------属性定义区开始-------------------------*/
            
            /*----------------------------属性定义区结束-------------------------*/
            /*----------------------------方法定义区开始-------------------------*/
            /*
            获得指定大小矩形的左上定点的坐标
            */
            LeftPoint: function(width, height)
            {
                var sheight = window.screen.availHeight;
                var swidth = window.screen.availWidth;
                if (width > swidth || height > sheight)
                {
                    return;
                }
                var point = new Array();
                point.X = (swidth - width) / 2;
                point.Y = (sheight - height) / 2;
                return point;
            },
            //改变窗口大小为指定ID控件大小，并使窗体居中
            ResizeWind: function(id)
            {
                var WinWidthMore = 5;
                var WinHeightMore = 5;
                var obj = document.getElementById(id);
                var winWidth = parseInt(obj.clientWidth) + parseInt(WinWidthMore);
                var winHeight = parseInt(obj.clientHeight) + parseInt(WinHeightMore);
                window.resizeTo(winWidth, winHeight);

                var point = jQuery.LeftPoint(winWidth, winHeight);
                window.moveTo(point.X, point.Y);
            },
            winOpenFullScreen: function(strURL, strName)
            {
                width = screen.availWidth;
                height = screen.availHeight;
                theWindow = window.open(strURL, strName, "status=no,scrollbars=yes,resizable=yes,left=0,top=0,width=" + width + ",height=" + (height - 50));
                if (theWindow.opener == null) theWindow.opener = window;
                if (window.focus) theWindow.focus();
            },
            /*
            打开无边框的允许改变大小和滚动条的窗体
            */
            winOpenCenterHalf: function(strURL, strName, width, height)
            {
                if (parseInt(width) && parseInt(height))
                {
                    theWindow = window.open(strURL, strName, "width=" + width + ",height=" + height + ",scrollbars=yes,resizable=yes,left=" + (1024 - width) / 2 + ",top=" + (768 - height) / 2);
                    if (theWindow.opener == null) theWindow.opener = window;
                    if (window.focus) theWindow.focus();
                }
                else
                {
                    theWindow = window.open(strURL, strName, 'left=' + (window.screen.width / 4) + ',top=' + (window.screen.height / 4) + ',status=yes,fullscreen=yes,toolbar=yes,menubar=yes,location=yes,scrollbars=yes,resizable=yes');
                    if (theWindow.opener == null) theWindow.opener = window;
                    if (window.focus) theWindow.focus();
                }
            },
            //打开无边框的固定大小的窗体
            winOpenFixedCenterHalf: function(strURL, strName, width, height)
            {
                if (parseInt(width) && parseInt(height))
                {
                    theWindow = window.open(strURL, strName, "width=" + width + ",height=" + height + ",scrollbars=yes,resizable=no,left=" + (window.screen.width - width) / 2 + ",top=" + (window.screen.height - height) / 2);
                    if (theWindow.opener == undefined || theWindow.opener == null || theWindow.opener == "undefined") theWindow.opener = window;
                    if (window.focus) theWindow.focus();
                }
                else
                {
                    theWindow = window.open(strURL, strName, 'left=' + (window.screen.width / 4) + ',top=' + (window.screen.height / 4) + ',status=yes,fullscreen=yes,toolbar=yes,menubar=yes,location=yes,scrollbars=yes,resizable=yes');
                    if (theWindow.opener == null) theWindow.opener = window;
                    if (window.focus) theWindow.focus();
                }
            },
            //打开居中模式窗口，允许有滚动条和改变大小
            ModalDlg: function(url, width, height)
            {
                //var obj = window.showModalDialog(url.toString(),'dialogWidth:'+width.toString()+'px;dialogHeight:'+height.toString()+'px;center:yes;resizable:yes;scroll:yes');
                //改成模式窗口后：     	
                var param = new Array();
                window.showModalDialog(url.toString(), param, 'dialogWidth:' + width.toString() + 'px;dialogHeight:' + height.toString() + 'px;dialogLeft=' + window.event.x + ';dialogTop=' + window.event.y + ';center:yes;resizable:no;scroll:yes;status=no;help=no;');
                return param;
            },
            /*确认以后转到一个地址,用于修改状态等操作的确定上*/
            confirmWinOpen: function(msg, url, width, height)
            {
                result = true;
                if (confirm(msg))
                {
                    if (width != null && height != null)
                    {
                        if (parseInt(width) && parseInt(height))
                        {
                            window.open(url, '', "width=" + width + ",height=" + height + ",top=0,left=80")
                        }
                        else
                        {
                            alert("宽高参数值非整数!");
                        }
                    }
                    else
                    {
                        window.location.href = url;
                    }
                }
                else
                {
                    result = false;
                }
                return result;
            },
            RefreshParent: function(flag)
            {
                window.opener.location.href = window.opener.location.href;
                if (flag == true) window.close();
            }
            /*----------------------------方法定义区结束-------------------------*/
        };
        /*****************************XJWindow库结束***************************/
    }
    /*################################命名空间结束###########################*/
})();